package com.videoweb.controller;

import com.videoweb.service.IVideoLikeService;
import com.videoweb.utils.AjaxResult;
import com.videoweb.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lmr
 * @since 2025-05-17
 */
@RestController
@RequestMapping("/vlike")
public class VideoLikeController {

    @Autowired
    private IVideoLikeService videoLikeService;

    /**
     * 检查用户是否点赞了该视频
     */
    @GetMapping("/check/{id}")
    public AjaxResult checkLike(@PathVariable("id") Long videoId) {
        boolean liked = videoLikeService.checkLike(videoId);
        return AjaxResult.success("查询成功", liked);
    }

    /**
     * 点赞
     */
    @PostMapping("/like/{id}")
    public AjaxResult likeIt(@PathVariable("id") Long videoId) {
        boolean result = videoLikeService.likeIt(videoId);
        if (result) {
            return AjaxResult.success("点赞成功");
        } else {
            return AjaxResult.error("点赞失败");
        }
    }

    /**
     * 取消点赞
     */
    @PostMapping("/cancel/{id}")
    public AjaxResult cancelLike(@PathVariable("id") Long videoId) {
        boolean result = videoLikeService.cancelLike(videoId);
        if (result) {
            return AjaxResult.success("取消点赞成功");
        } else {
            return AjaxResult.error("取消点赞失败");
        }
    }
}
